#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/3/22 10:35
# @Author : 闫峰
# @File    : ErpDesUtil.py

import hashlib
from Crypto.Cipher import DES
from Crypto.Util.Padding import pad

def md5X32(text):
    md5 = hashlib.md5()
    md5.update(text.encode('utf-8'))
    return md5.hexdigest().upper()

def desEncode(text):
    key = md5X32("irobotbox").encode('utf-8')[:8]
    iv = md5X32("irobotbox").encode('utf-8')[:8]
    des = DES.new(key, DES.MODE_CBC, iv)
    padded_text = pad(text.encode('iso-8859-1'), DES.block_size)
    encrypted_text = des.encrypt(padded_text)
    return encrypted_text.hex().upper()

